package CutLoad.cookies
{
	import flash.events.*;
	import flash.net.NetConnection;
	import flash.net.Responder;
	
	/**
	 * 连接amfphp 
	 * @author smallerbird mail:smallerbird@gmail.com  site:www.mkigm.com QQ群:49983196
	 * 
	 */	
	public class CAmfphp
	{
		private var gateway:String;
		private var connection:NetConnection;
		private var responder:Responder;
		private var funResult:Function=null,funFault:Function=null;
		public function CAmfphp(url:String)
		{
			gateway=url;
			responder = new Responder(onResult, onFault);
			connection = new NetConnection;
			connection.connect(gateway);
		}
		public function getResponder():Responder{
			return responder;
		}
		/**
		 * 设置返回结果处理的方法
		 * @param funResult 返回结果的处理方法  格式：function(返回结果:Object)
		 * @param funFault 如果期间发生错误要处理的方法  格式：function(返回结果:Object)
		 * 
		 * @return 
		 * 
		 */		
		public function setCallDo(funResult:Function=null,funFault:Function=null):NetConnection{
			this.funResult=funResult;
			this.funFault=funFault;		
			return connection;
		}
		// Handle a successful AMF call. This method is defined by the responder. 
		private function onResult(result:Object):void {
			if(funResult!=null) funResult(result);
		}
		// Handle an unsuccessfull AMF call. This is method is dedined by the responder. 
		private function onFault(fault:Object):void {
			if(funFault!=null) funFault(funFault);
		}
	}
}